package com.shennong.mapper;

import com.shennong.pojo.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 符整国
 * @version 1.0
 */
@Mapper
public interface UserMapper {

    /**
     * 根据用户名和密码查询用户信息
     * @param loginDTO
     * @return
     */
    @Select("select * from scs.users where username = #{username} and password = #{password}")
    LoginVO getByUsernameAndPassword(LoginDTO loginDTO);

    /**
     * 根据用户名查询用户信息
     * @return
     */
    @Select("select * from scs.users where username = #{username}")
    User getByUsername();


    /**
     * 新增用户
     * @param user
     */
    @Insert("insert into scs.users(username,password,name,email,created_time) values(#{username},#{password},#{name},#{email},#{createTime})")
    void insert(User user);

    /**
     * 根据用户id查询课程信息
     *
     * @param id
     * @return
     */
    @Select("select * from scs.courses where id in (select course_id from scs.enrollments where user_id = #{id})")
    List<Course> getCourseByUserId(Integer id);

    /**
     * 查询所有课程信息
     *
     * @return
     */
    @Select("select * from scs.courses")
    List<Course> findAllCourse();

    /**
     * 根据用户id和课程id查询选课信息
     *
     * @param enrollment
     */

    void selectCourse(Enrollment enrollment);

    /**
     * 取消选课
     *
     */
    void cancelCourse(Enrollment enrollment);

    /**
     * 请假
     *
     * @param leave
     */
    void leave(Leave leave);

    @Select("select * from scs.leaves where user_id = #{id}")
    Leave getLeaveByUserId(Integer id);
}
